clear
rng default
addpath /Users/tew647/mosek/9.3/toolbox/r2015aom

%% Load useful matrices
load PXY_cond 
load V_CS

%% Construct grid of parameters to check 
u01grid=0; %location normalisation [Xchosen=0, Y=1]
u02grid=0; %location normalisation
u11grid=V_11_CS; %scale normalisation
gran=0.5; 
u12grid=-20:gran:20;  
u22grid=-20:gran:20;  
u21grid=-20:gran:20; 
% try different values of gran and different sizes of grid hypercube as discussed in Appendix C of the paper (need powerful cluster to run the code for higher values of gran and larger sizes of hypercube)
[ca, cb, cc, cd, ce, cf] = ndgrid(u01grid, u11grid, u21grid, u02grid, u12grid, u22grid);
u01grid=ca(:);
u11grid=cb(:);
u21grid=cc(:);
u02grid=cd(:);
u12grid=ce(:);
u22grid=cf(:);
sg=size(u12grid,1);

%% Components invariant across parameter values
[equalorder, ...
Ugridreduced, sgreduced,...
id_Ugridreduced,...
s_id_gridreduced, sU_id_gridreduced,...
n_U_sets, Tcoord, indices_pairs,...
numeqconstraints,coordrowseq, fillAeq, beq]=useful_anyparam1_ind(u01grid, u11grid, u21grid,u02grid, u12grid, u22grid, sg, PXY_cond);      

%% Identified set
IdSetW_final=OneSide1_ind(u01grid, u11grid, u21grid,u02grid, u12grid, u22grid,...
                            equalorder, ...
                            Ugridreduced, sgreduced,...
                            id_Ugridreduced,...
                            s_id_gridreduced, sU_id_gridreduced,...
                            n_U_sets, Tcoord, indices_pairs,...
                            numeqconstraints,coordrowseq, fillAeq, beq);  

save('IdSetW_final.mat', 'IdSetW_final')